/**
 * author:Administrator
 * date:2015/7/27
 * desc:TODO
 */

"use strict";

var mongoose = require('../mongodb.js');
var Schema = mongoose.Schema;

let PermissionSchema = new Schema({
    groupName: {type: String, required: true},
    name: {type: String, required: true},
    uniqueName: {type: String, required: true, unique: true},
    createdAt: {type: Date, default: Date.now},
    updatedAt: Date
});

PermissionSchema.pre('save', function (next) {
    if (!this.updatedAt) {
        this.updatedAt = new Date();
    }
    next();
});

// 指定collection name，默认是复数
var permission = mongoose.model('permission', PermissionSchema, 'permission');
exports = module.exports = permission;